package com.eastmelon.javase;

public class ThreadTest {
	public static void main(String[] args) {

		Thread thread = new Thread() {

			@Override
			public void run() {
				while (true) {
					try {
						Thread.sleep(500);
					}
					catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println(this.getName());
				}
			}
		};
		thread.start();
		Thread thread2 = new Thread(new Runnable() {
			public void run() {
				while (true) {
					try {
						Thread.sleep(500);
					}
					catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println(Thread.currentThread().getName());
				}
			}
		});
		thread2.start();
		// 创建线程的两种方式
		new Thread(new Runnable() {
			public void run() {
				System.out.println("1");
			}
		}) {
			@Override
			public void run() {
				System.out.println("2");
			}
		}.start();//运行结果会输出2，因为子类重写了父类的方法
	}
}
